#ifndef __CTIMER_MANGER_H_
#define __CTIMER_MANGER_H_
#include "timer.h"

#ifndef WIN32
#include <sys/time.h>
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#endif

#define DEFULT_INTERVAL 1000   
#define DEFAUL_REPAIR 20
class CTimerManager
{
public:
	
	typedef enum
	{
		TIMER_MANAGER_STOP=0,
		TIMER_MANAGER_START
	}TimerManagerState;
	
	static CTimerManager * instance();
	void add_timer(CTimer * vtimer);
	void remove_timer(CTimer * vtimer);
	void start(unsigned long interval=DEFULT_INTERVAL,unsigned long repair=DEFAUL_REPAIR);
	void stop();
	void dump();
protected:
	static void * process(void *);
	void *        _process();
private:	
	void add_timer_(CTimer * vtimer);
	void remove_timer_(CTimer * vtimer);
	
	CTimerManager();
#ifndef WIN32
	static pthread_mutex_t m_mutex;
	TAILQ_HEAD(,CTimer) list_;
#endif
	static CTimerManager * m_instance;
	
	TimerManagerState m_state;
	struct timeval m_interval;
	struct timeval m_repair;
	std::list<CTimer*> list_;

	static unsigned int mark;
public:
		LOG4CPLUS_CLASS_DECLARE( _s_logger );
};
#endif
